//index.js
const config = require('../../config');
//获取应用实例
const app = getApp()

Page({
  data: {
    swiperCurrent: 0,
    count: 0,
    bannList: [],
    artiList: [],
    equList:[],
  },
  swiperChange: function (e) {
    this.setData({
      swiperCurrent: e.detail.current
    })
  },
  // 器材列表
  equipList: function () {
    var that = this;
    wx.request({
      url: config.artList,
      method: 'GET',
      data: {
        num: 7,
        type: 1,
      },
      header: {
        'content-type': 'application/json',
        'Authorization': wx.getStorageSync('token_type') + ' ' + wx.getStorageSync('access_token'),
      },
      success: function (res) {
        that.setData({
          equList: res.data.data
        })
        // console.log(res, "equList")
      }
    })
  },
  // 轮播图列表
  bannerList: function() {
    var that = this;
    wx.request({
      url: config.bannerList,
      method: 'GET',
      data: {
        num: 3,
      },
      header: {
        'content-type': 'application/json',
        'Authorization': wx.getStorageSync('token_type') + ' ' + wx.getStorageSync('access_token'),
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          bannList: res.data.data
        })
        // console.log(res, "artList")
      }
    })
  },
  // 文章列表
  artistList: function () {
    var that = this;
    wx.request({
      url: config.artList,
      method: 'GET',
      data: {
        num: 2,
        type: 2,
      },
      header: {
        'content-type': 'application/json',
        'Authorization': wx.getStorageSync('token_type') + ' ' + wx.getStorageSync('access_token'),
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          artiList: res.data.data,
          count: res.data.data.length,
        })
        // console.log(res, "artList")
      }
    })
  },
  // 跳转更多健身器材
  seeMaterial: function () {
    wx.navigateTo({
      url: '/pages/material/material'
    })
  },
  // 跳转更多健身指南
  seeGuide: function () {
    wx.navigateTo({
      url: '/pages/guide/guide'
    })
  },
  // 跳转健身器材详情
  seeDetail: function (e) {
    console.log(e.currentTarget.id)
    wx.navigateTo({
      url: '/pages/article/article?id=' + e.currentTarget.id
    })
  },

  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    wx.showLoading({
      title: '加载中',
    })
    this.bannerList();
    this.equipList();
    this.artistList();
  },

  onShow: function () {
    
  },
  // getUserInfo: function(e) {
  //   console.log(e)
  //   app.globalData.userInfo = e.detail.userInfo
  //   this.setData({
  //     userInfo: e.detail.userInfo,
  //     hasUserInfo: true
  //   })
  // }
})
